$(function(){
    window.onload = function(){
        menuFixed('form-link');
    }
    $('#defaultForm').validationEngine();
});
function menuFixed(id){
    var obj = document.getElementById(id);
    var _getHeight = obj.offsetTop;

    window.onscroll = function(){
        changePos(id,_getHeight);
    }
}
function changePos(id,height){
    console.log(height);
    var obj = document.getElementById(id);
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    if(scrollTop < height){
        obj.style.top='0';
        obj.style.left='0';
        obj.style.position = 'relative';
    }else{
        obj.style.position = 'fixed';
    }
}

function goto_detail(cust_id){
    window.location.href="../../customer/customer/customer_detail?cust_id="+cust_id;
}

function goto_basic(cust_id){
    window.location.href="../../customer/customer/customer_basic?cust_id="+cust_id;
}
function goto_work(cust_id){
    window.location.href="../../customer/customer/customer_work?cust_id="+cust_id;
}
function goto_linkman(cust_id){
    window.location.href="../../customer/customer/customer_linkman?cust_id="+cust_id;
}

function update_ajax_cust(url){
    if(!$("#defaultForm").validationEngine("validate")){
        return false;
    };
    $.ajax({
        type: "post",
        async: true,
        data: $("#defaultForm").serialize(),
        url: url,
        success: function(d){
            console.log(d);
            if(d==1){
                alert("修改客户基本资料成功！");
                window.location.reload();
            }else{
                alert("修改客户基本资料失败！");
                window.location.reload();
            }
        },
        error: function(e){
            alert("网络错误，请联系管理员");
        }
    });
}

function reset(){
    $("#defaultForm")[0].reset();
}

function close_tab(){
    var title="客户信息管理";
    var url="../../customer/customer/customer_manage";
    window.parent.removeTab(title,url);
}

function validate_identity(){
    var cust_name=$("#cust_name").val();
    var cust_identity=$("#cust_identity").val();

    if(cust_name==''||cust_name==null){
        alert("姓名不能为空");
        return;
    }
    if(cust_identity==''||cust_identity==null){
        alert("身份证不能为空");
        return;
    }
    var data={"cust_name":cust_name,"cust_identity":cust_identity};
    var url="../../customer/validateApi/validate_identity";
    $.ajax({
        type: "post",
        async: true,
        data: data,
        url: url,
        success: function(d){
            console.log(d);
            if(d==1){
                alert("修改客户基本资料成功！");
                window.location.reload();
            }else{
                alert("修改客户基本资料失败！");
                window.location.reload();
            }
        },
        error: function(e){
            alert("网络错误，请联系管理员");
        }
    });
}
